package com.fxu.gen.cloud;

import com.fxu.gen.AutoUtil;
import com.fxu.gen.Base;
import com.fxu.gen.enums.TplEnum;
import com.fxu.tpl.entity.Table;
import com.fxu.tpl.enums.ProjectTypeEnum;

import java.io.File;
import java.util.Objects;

/**
 * ServiceImpl类的模板替换
 */
public final class ServiceImpl extends Base {
	
	public ServiceImpl(Table table, File destFile) {
		super(table, TplEnum.ServiceImpl, destFile);
	}
	
	@Override
    public String doReplace() {
		String fileTxt = super.doReplace();
		if (Objects.equals(table.getProject().getType(), ProjectTypeEnum.SPRING_BOOT.code()) && !destFileExist) {
			fileTxt = fileTxt.replace("@RequestMapping(\"/remote/"+AutoUtil.firstLowerBean(table.getName())+"\")\r\n", "");
			fileTxt = fileTxt.replace("@RestController", "@Component");
			//org.springframework.web.bind.annotation.RestController=>org.springframework.stereotype.Component
			fileTxt = fileTxt.replace("import org.springframework.web.bind.annotation.RestController", "import org.springframework.stereotype.Component");

			fileTxt = fileTxt.replace("import java.util.Map;\r\n", "");
			fileTxt = fileTxt.replace("import javax.validation.Valid;\r\n", "");
			fileTxt = fileTxt.replace("import org.springframework.web.bind.annotation.RequestMapping;\r\n", "");
			fileTxt = fileTxt.replace("import org.springframework.web.bind.annotation.PathVariable;\r\n", "");
			fileTxt = fileTxt.replace("import org.springframework.web.bind.annotation.RequestBody;\r\n", "");
			fileTxt = fileTxt.replace("import org.springframework.web.bind.annotation.GetMapping;\r\n", "");
			fileTxt = fileTxt.replace("import org.springframework.web.bind.annotation.PostMapping;\r\n", "");
		}
		return fileTxt;
	}
}
